import React, {Component} from 'react'
import {View, Text, Platform, StyleSheet, Animated, Image} from 'react-native'
import {storage} from '../utils/storage'


export default class Splash extends Component {
    constructor(props) {
        super(props);
        this.state = {
            fadeAnim: new Animated.Value(0),
        }
    }

    componentDidMount() {
        const {navigation} = this.props;
        Animated.timing(this.state.fadeAnim,{
            toValue:1,
            duration:2000
        }).start();

        this.timer = setTimeout(async ()=> {
            let isFirst = await storage.load('isFirst');
            if(!isFirst) {
                storage.save('isFirst',true)
                navigation.navigate('GuildPage')
            }else {
                storage.remove('isFirst')
                navigation.navigate('HomePage')
            }
        },2000)
    }

    componentWillUnmount() {
        clearTimeout(this.timer)
    }

    render() {
        return (
            <Animated.Image
                style={{
                    width: '100%',
                    height: '100%',
                    resizeMode: 'stretch',
                    opacity: this.state.fadeAnim}}
                source={require('../assets/images/banner.jpg')}
            />
        )
    }

}

const styles = StyleSheet.create({

})

